package org.fujene.structure;

// 単語の管理に利用します。
public final class SearchedTerm{
	private String term;
	private LookupPointer ptr;
	private LookupPointer next;
	private LookupPointer prev;
	private LookupPointer docIDs;

	private long termHash;
	private long firstDocID;
	private int skipPtrIndex;
	private boolean addSkipPtr;

	public SearchedTerm(String term, LookupPointer ptr, LookupPointer next, LookupPointer docIDs){
		this(term, ptr, next, docIDs, 0);
	}

	public SearchedTerm(String term, LookupPointer ptr, LookupPointer next, long hash, LookupPointer docIDs,
			long firstID){
		this(term, ptr, next, docIDs, 0);
		this.termHash = hash;
		this.firstDocID = firstID;
	}

	public SearchedTerm(String term, LookupPointer ptr, LookupPointer next, LookupPointer docIDs,
			int skipPtrIndex){
		this(term, ptr, null, next, docIDs, skipPtrIndex);
	}

	public SearchedTerm(String term, LookupPointer ptr, LookupPointer prev, LookupPointer next,
			LookupPointer docIDs, int skipPtrIndex){
		this(term, ptr, prev, next, docIDs, skipPtrIndex, false);
	}

	public SearchedTerm(String term, LookupPointer ptr, LookupPointer prev, LookupPointer next,
			LookupPointer docIDs, int skipPtrIndex, boolean addSkipPtr){
		this.term = term;
		this.ptr = ptr;
		this.prev = prev;
		this.next = next;
		this.docIDs = docIDs;
		this.skipPtrIndex = skipPtrIndex;
		this.addSkipPtr = addSkipPtr;
	}

	public SearchedTerm(long firstDocID, LookupPointer ptr, LookupPointer prev, LookupPointer next,
			boolean addSkipPtr, int skipPtrIndex){
		this.firstDocID = firstDocID;
		this.ptr = ptr;
		this.prev = prev;
		this.next = next;
		this.addSkipPtr = addSkipPtr;
		this.skipPtrIndex = skipPtrIndex;
	}

	public String getTerm(){
		return term;
	}

	public LookupPointer getPrev(){
		return prev;
	}

	public LookupPointer getNext(){
		return next;
	}

	public LookupPointer getPtr(){
		return ptr;
	}

	public LookupPointer getDocIDs(){
		return docIDs;
	}

	public int getSkipPtrIndex(){
		return skipPtrIndex;
	}

	public long getTermHash(){
		return termHash;
	}

	public long getFirstDocID(){
		return firstDocID;
	}

	public void setPtr(LookupPointer ptr){
		this.ptr = ptr;
	}

	public void setPrev(LookupPointer prev){
		this.prev = prev;
	}

	public void setNext(LookupPointer next){
		this.next = next;
	}

	public void setSkipPtrIndex(int skipPtrIndex){
		this.skipPtrIndex = skipPtrIndex;
	}

	public boolean isMakeSkip(){
		return this.addSkipPtr;
	}

	public String toString(){
		return new String("Term: " + this.term + " at " + (this.ptr != null ? this.ptr.toString() : " -- ")
				+ "\n  hash: " + (this.termHash) + "\n  next: "
				+ (this.next != null ? this.next.toString() : " -- ") + "\n  prev: "
				+ (this.prev != null ? this.prev.toString() : " -- ") + "\n  docIDs at: "
				+ (this.docIDs != null ? this.docIDs.toString() : " -- ")
				+ "\n  Distribute at skip pointer: " + this.skipPtrIndex);
	}

	public void setFirstDocID(long firstDocID){
		this.firstDocID = firstDocID;
	}
}
